//
//  LawDetailsView.m
//  yonghu
//
//  Created by 浪尖渝力 on 2018/1/19.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "LawDetailsView.h"
#import "ReleaseAdviceViewController.h"
@implementation LawDetailsView
-(void)creatView{
    self.backgroundColor=[UIColor whiteColor];
    
    _scrollView=[UIScrollView new];
    [self addSubview:_scrollView];
    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(NAV_HEIGHT);
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    _scrollView.scrollsToTop =NO;
    _scrollView.showsVerticalScrollIndicator = FALSE;
    _scrollView.showsHorizontalScrollIndicator = FALSE;
    _scrollView.bounces = NO;
    
    if (@available(iOS 11.0, *)) {
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.viewController.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    NSString *news_title=[_dic objectForKey:@"law_qa_question"];
    
    CGSize size1=[ZQTools getNSStringSize:news_title andViewWight:_mainW-30 andFont:20];
    
    UILabel *titleLabel=[UILabel new];
    [_scrollView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(20);
        make.width.mas_equalTo(_mainW-30);
    }];
    titleLabel.numberOfLines=0;
    titleLabel.text=news_title;
    titleLabel.textColor=ColorWithRGB(49, 49, 49);
    titleLabel.font=[UIFont systemFontOfSize:20];
    titleLabel.textAlignment=NSTextAlignmentCenter;
    
    
    
    NSString *news_author=[_dic objectForKey:@"law_ct_name"];
    
    CGSize size10=[ZQTools getNSStringWeight:news_author andViewWight:20 andFont:18];
    UILabel *authorLabel=[UILabel new];
    [_scrollView addSubview:authorLabel];
    [authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(titleLabel);
        make.top.mas_equalTo(titleLabel.mas_bottom).mas_equalTo(25);
        make.width.mas_equalTo(_mainW*0.3);
    }];
    authorLabel.text=news_author;
    authorLabel.font=[UIFont systemFontOfSize:16];
    authorLabel.layer.borderWidth=1;
    authorLabel.layer.borderColor=ColorWithRGB(132, 189,226).CGColor;
    authorLabel.textColor=ColorWithRGB(132, 189,226);
    [authorLabel layoutIfNeeded];
    authorLabel.textAlignment=NSTextAlignmentCenter;
    authorLabel.layer.cornerRadius=4;
    
    NSNumber *time=[_dic objectForKey:@"law_qa_time"];
    
    UILabel *timeLabel=[UILabel new];
    [_scrollView addSubview:timeLabel];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(titleLabel);
        make.centerY.mas_equalTo(authorLabel);
        make.width.mas_equalTo(_mainW*0.6);
    }];
    NSString *news_time=[ZQTools changeTimeCuo:@"yyyy-MM-dd HH:mm":[NSString stringWithFormat:@"%@",time] ];
    timeLabel.text=[NSString stringWithFormat:@"发布时间:%@",news_time];
    timeLabel.font=[UIFont systemFontOfSize:16];
    timeLabel.textColor=ColorWithRGB(149, 149, 149);
    timeLabel.textAlignment=NSTextAlignmentCenter;
    
    NSString *news_content=[_dic objectForKey:@"law_qa_answer"];
    
 
    
    UILabel *contentLabel=[UILabel new];
    [_scrollView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(timeLabel.mas_bottom).mas_equalTo(15);
        make.width.mas_equalTo(_mainW-30);
    }];
    contentLabel.numberOfLines=0;
    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[news_content  dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSFontAttributeName:[UIFont systemFontOfSize:18.0f] } documentAttributes:nil error:nil];
    contentLabel.attributedText = attrStr;
    
    contentLabel.textColor=ColorWithRGB(99, 99, 99);
    contentLabel.font=[UIFont systemFontOfSize:18];
    
     CGSize size2=[ZQTools getNSStringSize:[NSString stringWithFormat:@"\t%@",contentLabel.text] andViewWight:_mainW-30 andFont:18];
    
    _scrollView.contentSize = CGSizeMake(0,_mainH*0.25+370+size1.height+size2.height);
    
    UIButton *btn=[UIButton new];
    [self addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
        make.bottom.mas_equalTo(0);
    }];
    btn.backgroundColor=_backgroundColor;
    [btn setTitle:@"立即咨询" forState:0];
    [btn setTitleColor:[UIColor whiteColor] forState:0];
    [btn addTarget:self action:@selector(payBtn:) forControlEvents:UIControlEventTouchUpInside];
}
-(IBAction)payBtn:(UIButton *)btn{
    ReleaseAdviceViewController *fabu=[[ReleaseAdviceViewController alloc] init];
    [ZQTools pushNextViewController:self.viewController  andRootController:fabu];
}
@end
